package com.liang.demo.service.impl;

import com.liang.demo.mapper.ResourceMapper;
import com.liang.demo.po.Resource;
import com.liang.demo.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 陈琪亮
 * @version 1.0
 * @date 2021/3/21 15:39
 */
@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public Set<String> getPermissionByUserId(String adminId) {
        List<Resource> resources = resourceMapper.getPermission(Long.parseLong(adminId));
        Set<String> permissionStr = new HashSet<>();
        resources.forEach(r -> permissionStr.add(r.getUrl()));
        return permissionStr;
    }

    @Override
    public List<Resource> getResourceAll() {
        List<Resource> resources = resourceMapper.getResourceAll();
        return resources;
    }
}
